package panels;

import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.*;

public class FieldNameRenderer extends DefaultTableCellRenderer {
	private ImageIcon keyIcon = null;
	private ImageIcon primaryKeyIcon = null;
	private String keyPath = "/frame/icon/key.PNG";
	private String primaryKeyPath = "/frame/icon/mainkey.PNG";

	public FieldNameRenderer() {
		Class tc = this.getClass();
		keyIcon = new ImageIcon(tc.getResource(keyPath));
		primaryKeyIcon = new ImageIcon(tc.getResource(primaryKeyPath));
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if (((Boolean) table.getValueAt(row, 4)).booleanValue())
			this.setIcon(this.primaryKeyIcon);
		else
			this.setIcon(keyIcon);
		this.setText((String) value);

		if (isSelected) {
			this.setForeground(table.getSelectionForeground());
			this.setBackground(table.getSelectionBackground());
		} else {
			this.setForeground(table.getForeground());
			this.setBackground(table.getBackground());
		}
		return this;
	}
}